/**
 * Usage:
 * <a onclick="return SF.Utility.Social.shareFacebook('https://example.com');" href="#"><img src="facebook.png"></a>
 **/
var SF = {};
SF.Utility = {
	popup: function (a, b) {
		var c = b || {};
		c.target = c.target || a.target || "";
		c.width = c.width || 600;
		c.height = c.height || 600;
		var d = c;
		d || (d = {});
		var e = window, c = "undefined" != typeof a.href ? a.href : String(a), f = d.target || a.target, k = [], l;
		for (l in d)
			switch (l) {
				case "width":
				case "height":
				case "top":
				case "left":
					k.push(l + "=" + d[l]);
					break;
				case "target":
				case "noreferrer":
					break;
				default:
					k.push(l + "=" + (d[l] ? 1 : 0))
			}
		l = k.join(",");
		if (d.noreferrer) {
			if (d = e.open("", f, l))
				G && -1 != c.indexOf(";") && (c = "'" + c.replace(/'/g, "%27") + "'"), d.opener = 
				n, c = va(c), d.document.write('<META HTTP-EQUIV="refresh" content="0; url=' + c + '">'), d.document.close()
		} else
			d = e.open(c, f, l);
		c = d;
		if (!c)
			return n;
		c.opener || (c.opener = window);
		c.focus();
		return c
	}
};
SF.Utility.Social = {
	ShareObject: {
		getPopupLink: function(){
			this.prepare();
			var pairs = [];
			for (var param in this.params) {
				if (this.params[param] == null) {
					continue;
				}
				pairs.push(param + '=' + this.params[param]);
			}
			return this.link + '?' + pairs.join('&');
		},
		getPopupParams: function(){
			return this.popupParams;
		},
		popup: function(){
			SF.Utility.popup(this.getPopupLink(), this.getPopupParams());
			return false;
		}
	},
	Facebook: {
		appID: '131896876986796',
		redirectURI: 'http://blueup.vn',
		link: 'http://www.facebook.com/dialog/feed',
		params: {app_id: null, link: null, display: 'popup', redirect_uri: null},
		popupParams: {'height': 306, 'width': 650, 'scrollbars': true},

		prepare: function(){
		  this.params['link']			= this.url;
		  this.params['app_id']			= this.appID;
		  this.params['redirect_uri']	= this.redirectURI;
		}
	},
	Twitter: {
		via: '',
		link: 'http://twitter.com/share',
		params: {url: null, text: null, via: null},
		popupParams: {'height': 650,'width': 1024,'scrollbars': true},

		prepare: function(){
		  this.params['url']	= this.url;
		  this.params['text']	= this.title;
		  this.params['via']	= this.via;
		}
	},
	Google: {
		source: 'yt',
		link: 'https://plus.google.com/share',
		params: {url: null, source: null},
		popupParams: {'height': 620,'width': 620,'scrollbars': true},

		prepare: function(){
		  this.params['url']	= this.url;
		  this.params['source']	= this.source;
		}
	},
	LinkedIn: {
		source: '',
		link: 'http://www.linkedin.com/shareArticle',
		params: {url: null},
		popupParams: {'height': 650,'width': 1024,'scrollbars': true},

		prepare: function(){
		  this.params['url']		= this.url;
		  this.params['source']		= this.source;
		}
	},
	shareFacebook: function(url){
		if(!url)
			return;
		fb = $.extend({}, this.ShareObject, this.Facebook);
		fb.url = url;
		return fb.popup();
	},
	shareTwitter: function(url, title){
		if(!url)
			return;
		tw = $.extend({}, this.ShareObject, this.Twitter);
		tw.url = url;
		tw.title = title;
		return tw.popup();
	},
	shareGoogle: function(url){
		if(!url)
			return;
		gg = $.extend({}, this.ShareObject, this.Google);
		gg.url = url;
		return gg.popup();
	},
	shareLinkedIn: function(url){
		if(!url)
			return;
		li = $.extend({}, this.ShareObject, this.LinkedIn);
		li.url = url;
		return li.popup();
	}
};